package cn.com.sqlite.demo.dao.imp;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import cn.com.sqlite.demo.dao.BaseDao;

@Repository
public class BaseDaoImp<T> implements BaseDao<T> {

	@Autowired
	private SessionFactory sessionFactory;
	
	/**
	 * 获取Session对象
	 * @return
	 */
	public Session getSession(){
		return sessionFactory.getCurrentSession();
	}
	
	public boolean save(T t) throws Exception {
		//手动开启事物
//		Session session = getSession();
//		Transaction ta = session.beginTransaction();
//		JdbcTransaction tx = session.getTransaction().getLocalStatus()==LocalStatus.ACTIVE?(JdbcTransaction)session.getTransaction():(JdbcTransaction) session.beginTransaction(); 
		getSession().save(t);
//		tx.commit();
		return true;
		
	}

}
